#ifndef GRAPHIQUE_H
#define GRAPHIQUE_H


#include <GL/glew.h>

#include <qgl.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <map>
#include <math.h>
#include <qevent.h>
#include <qpixmap.h>
#include <qtimer.h>
#include <qcursor.h>
#include <SDL.h>

class Scene;
class Camera;
class Joystick;
class SceneXmlParser;
class FramebufferObject;
class Renderbuffer;

class Graphique : public QGLWidget {

Q_OBJECT
public:
	Graphique(QWidget* parent, const char* = 0, const QGLWidget* shareWidget = 0);
	~Graphique();
	void setScenes(SceneXmlParser *parser) {m_data = parser;};
	Scene* getCurrentScene(){return currentScene;};
	void setScene(Scene *s) {currentScene=s;};
	void setCamera(Camera *camera);

	void initGlew();


public slots:
	void updateFrame();

protected:
	void initializeGL();
	void paintGL( void );
	void resizeGL( int w, int h );
	void mousePressEvent( QMouseEvent* );
	void mouseMoveEvent( QMouseEvent* );
	void mouseReleaseEvent( QMouseEvent* );
	void keyPressEvent( QKeyEvent* );
	//void sendStatusMessage( char* );

private:
	void processMVTransform();
	void processJoy();
	Camera *m_cam;
	Joystick *joy;
	SceneXmlParser *m_data;
	Scene *currentScene;

//	 FramebufferObject *fbo;
//	 Renderbuffer *rb;

	float DiffX, DiffY, DiffX2, DiffY2, ratio;
	int  g_MouseX, g_MouseY, g_Button, framecount;
	bool capturing;

	GLuint texId;
	GLint currentDrawbuf;
	enum	 Mode { FLY_ORBIT, FLY_MOVE , FLY_TWIST , FIX_ORBIT, FIX_ZOOM, FIX_PAN, MOV_JOY, ZOOM_JOY , ORBIT_JOY ,NONE } g_Mode ;
	QTimer *timer;

	typedef std::map<QString, Scene*>::iterator scenes_iterator;
};

#endif
